home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 27 / Mac Magazin and MacEasy Magazine CD - Issue 27.iso / Grafik & Text / Sans-Faute⁄Grammaire ƒ / Adaptateurs / Sources des scripts (anglais) / Vérification Microsoft® Word 6 < prev    next >
Text File  |  1996-02-20  |  3KB  |  75 lines

  1. set kMaxDocSize to 10000 -- max number of characters of a document for checking it in one time
  2. set kMaxCheckingSFG to 32000 -- max number of characters that Sans-Faute/Grammaire can check
  3. set knbParagraphMaxToCheck to 25 -- max number of paragraphs sent to Sans-Faute/Grammaire
  4.  
  5.  
  6. tell application "Microsoft® Word 6"
  7.     set FrontDocPresent to exists front document
  8. end tell
  9.  
  10. if FrontDocPresent then
  11.     
  12.     set endParagraphIdx to 0
  13.     tell application "Microsoft® Word 6"
  14.         set nbParagraph to count paragraph of front document
  15.     end tell
  16.     repeat while endParagraphIdx < nbParagraph
  17.         -- try to collect a maximum of paragraphs
  18.         set paragraphIdx to endParagraphIdx + 1
  19.         tell application "Microsoft® Word 6"
  20.             set paragraphSize to (count character of paragraph paragraphIdx of front document) - 1
  21.         end tell
  22.         if paragraphSize > kMaxCheckingSFG then
  23.             display dialog "Le paragraphe " & paragraphIdx & " dépasse 32000 caractères. Sans-Faute/Grammaire ne peut pas le vérifier !"
  24.         end if
  25.         repeat while (paragraphIdx ≤ nbParagraph) and (paragraphSize > kMaxCheckingSFG)
  26.             set paragraphIdx to paragraphIdx + 1
  27.             if paragraphIdx ≤ nbParagraph then
  28.                 tell application "Microsoft® Word 6"
  29.                     set paragraphSize to (count character of paragraph paragraphIdx of front document) - 1
  30.                 end tell
  31.                 if paragraphSize > kMaxCheckingSFG then
  32.                     display dialog "Le paragraphe " & paragraphIdx & " dépasse 32000 caractères. Sans-Faute/Grammaire ne peut pas le vérifier !"
  33.                 end if
  34.             end if
  35.         end repeat
  36.         set startParagraphIdx to paragraphIdx
  37.         
  38.         set bunchSize to 0
  39.         set nbparagraphBunch to 0
  40.         set objToCheck to {}
  41.         repeat while (paragraphIdx ≤ nbParagraph) and (nbparagraphBunch < knbParagraphMaxToCheck) and (bunchSize + paragraphSize ≤ kMaxDocSize)
  42.             --   (paragraphSize ≤ kMaxCheckingSFG) is implicit
  43.             set bunchSize to bunchSize + paragraphSize
  44.             if paragraphSize > 0 then
  45.                 set objToCheck to objToCheck & {a reference to the text of the paragraph paragraphIdx of front document}
  46.                 set nbparagraphBunch to nbparagraphBunch + 1
  47.             end if
  48.             
  49.             set paragraphIdx to paragraphIdx + 1
  50.             if paragraphIdx ≤ nbParagraph then
  51.                 tell application "Microsoft® Word 6"
  52.                     set paragraphSize to (count character of paragraph paragraphIdx of front document) - 1
  53.                 end tell
  54.             end if
  55.         end repeat
  56.         
  57.         if (bunchSize = 0) and (paragraphIdx ≤ nbParagraph) and (paragraphSize ≤ kMaxCheckingSFG) then
  58.             set objToCheck to objToCheck & {a reference to the text of the paragraph paragraphIdx of front document}
  59.             set endParagraphIdx to paragraphIdx
  60.             set bunchSize to paragraphSize
  61.         else
  62.             set endParagraphIdx to paragraphIdx - 1
  63.         end if
  64.         
  65.         if bunchSize > 0 then -- cas be zero if the end of the document contains only paragraphs > 32000
  66.             -- tell Sans-Faute/Grammaire to check the content of the list of references and made changes in Application Microsoft Word
  67.             tell application "Sans-Faute/Grammaire 2"
  68.                 Checking objToCheck ClientAddress Application "Microsoft® Word 6"
  69.             end tell
  70.         end if
  71.     end repeat
  72. else
  73.     display dialog "Aucun document n'est ouvert dans Microsoft® Word 6 !"
  74. end if
  75.